/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vn.com.sml.SEFM.controller;

import java.text.DateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Date;
import java.util.Iterator;
import javax.persistence.RollbackException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.SystemException;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.mvc.SimpleFormController;
import vn.com.sml.SEFM.BUS.BankBUS;
import vn.com.sml.SEFM.BUS.CardBUS;
import vn.com.sml.SEFM.BUS.CardBlackBUS;
import vn.com.sml.SEFM.BUS.CitiesBUS;
import vn.com.sml.SEFM.BUS.IPBUS;
import vn.com.sml.SEFM.BUS.IPBlackBUS;
import vn.com.sml.SEFM.BUS.MerchantBUS;
import vn.com.sml.SEFM.BUS.PersonBUS;
import vn.com.sml.SEFM.BUS.fraudStandardBUS;
import vn.com.sml.SEFM.domain.Merchant;
import vn.com.sml.SEFM.domain.Ip;
import vn.com.sml.SEFM.domain.Banks;
import vn.com.sml.SEFM.domain.Card;
import vn.com.sml.SEFM.domain.Person;
import vn.com.sml.SEFM.domain.Transactions;
import vn.com.sml.SEFM.BUS.transactionBUS;
import vn.com.sml.SEFM.domain.Cardblacklist;
import vn.com.sml.SEFM.domain.Cities;
import vn.com.sml.SEFM.domain.Countries;
import vn.com.sml.SEFM.domain.Fraudstandard;
import vn.com.sml.SEFM.domain.Ipblacklist;


/** 
 *
 * @author Tunp
 */
public class AddTransactionController extends SimpleFormController implements Controller {
    private transactionBUS transBUS = new transactionBUS();
    private MerchantBUS dvcntBUS = new MerchantBUS();
    private IPBUS ipBUS = new IPBUS();
    private IPBlackBUS ipblackBUS = new IPBlackBUS();
    private CardBUS cardBUS = new CardBUS();
    private CardBlackBUS cardblackBUS = new CardBlackBUS();
    private BankBUS bankBUS = new BankBUS();
    private fraudStandardBUS fraudBUS = new fraudStandardBUS();
    private PersonBUS personBUS = new PersonBUS();
    private CitiesBUS cityBUS = new CitiesBUS();

    public void setCityBUS(CitiesBUS cityBUS) {
        this.cityBUS = cityBUS;
    }

    public void setPersonBUS(PersonBUS personBUS) {
        this.personBUS = personBUS;
    }

    public void setBankBUS(BankBUS bankBUS) {
        this.bankBUS = bankBUS;
    }

    public void setCardBUS(CardBUS cardBUS) {
        this.cardBUS = cardBUS;
    }

    public void setCardblackBUS(CardBlackBUS cardblackBUS) {
        this.cardblackBUS = cardblackBUS;
    }

    public void setDvcntBUS(MerchantBUS dvcntBUS) {
        this.dvcntBUS = dvcntBUS;
    }

    public void setFraudBUS(fraudStandardBUS fraudBUS) {
        this.fraudBUS = fraudBUS;
    }

    public void setIpBUS(IPBUS ipBUS) {
        this.ipBUS = ipBUS;
    }

    public void setIpblackBUS(IPBlackBUS ipblackBUS) {
        this.ipblackBUS = ipblackBUS;
    }

    public void setTransBUS(transactionBUS transBUS) {
        this.transBUS = transBUS;
    }
     
    
    public AddTransactionController() {
        //Initialize controller properties here or 
        //in the Web Application Context

//        setCommandClass(Transactions.class);
//        setCommandName("trans");
//        setSuccessView("successView");
//        setFormView("addTransaction");
    }
    
    @Override
	public ModelAndView handleRequest(HttpServletRequest arg0,
			HttpServletResponse arg1) throws Exception {
     
        String newtrans = arg0.getParameter("newtrans");
        
        
        if(newtrans==null) {
            ModelAndView mv = new ModelAndView("addTransaction");

            List<Cities> lstCities = cityBUS.listCities();
            mv.addObject("lstCities",lstCities);
            
            List<Countries> lstCountries = cityBUS.listCountries();
            mv.addObject("lstCountries",lstCountries);
        
            return mv;
        }
        else {
            String transId = arg0.getParameter("transId");
            String transType = arg0.getParameter("transType");
            String transDate = arg0.getParameter("transDate"); //Date
            String orderInfoId = arg0.getParameter("orderInfoId");
            String cardnumber = arg0.getParameter("cardnumber");
            String cardholder = arg0.getParameter("cardholder");
            String bankId = arg0.getParameter("bankId");
            String ip = arg0.getParameter("ip");
            String merchantId = arg0.getParameter("merchantId");
            String expectReceiveDate = arg0.getParameter("expectReceiveDate"); //Date
            String responsecode = arg0.getParameter("responsecode");
            String amount = arg0.getParameter("amount");

             String buyername = arg0.getParameter("buyername");
            String buyergender = arg0.getParameter("buyergender");
            String buyercountry = arg0.getParameter("buyercountry");
            String buyercity = arg0.getParameter("buyercity");
            String buyeraddress = arg0.getParameter("buyeraddress");
            String buyeremail = arg0.getParameter("buyeremail");
            String buyertel = arg0.getParameter("buyertel");
            String buyerphone = arg0.getParameter("buyerphone");
            String buyerfax = arg0.getParameter("buyerfax");

             String Receivername = arg0.getParameter("Receivername");
            String Receivergender = arg0.getParameter("Receivergender");
            String Receivercountry = arg0.getParameter("Receivercountry");
            String Receivercity = arg0.getParameter("Receivercity");
            String Receiveraddress = arg0.getParameter("Receiveraddress");
            String Receiveremail = arg0.getParameter("Receiveremail");
            String Receivertel = arg0.getParameter("Receivertel");
            String Receiverphone = arg0.getParameter("Receiverphone");
            String Receiverfax = arg0.getParameter("Receiverfax");
            
            Cities buyer_city = cityBUS.getCitiesById(Integer.parseInt(buyercity));
            Cities receiver_city = cityBUS.getCitiesById(Integer.parseInt(Receivercity));
            
            Person buyer = new Person(buyer_city, buyername, getgender(buyergender), buyeraddress, buyeremail, buyertel, buyerphone, buyerfax, null, null);
            
            Person receiver = new Person(receiver_city, Receivername, getgender(Receivergender), Receiveraddress, Receiveremail, Receivertel, Receiverphone, Receiverfax, null, null);
            
            DateFormat fm = DateFormat.getDateInstance(DateFormat.SHORT);
            Date expectReceive = fm.parse(expectReceiveDate);
            Date transacDate = fm.parse(transDate);
            
            
            Transactions transac = new Transactions(buyer, receiver, bankId, merchantId, ip, cardnumber, transId, orderInfoId, expectReceive, cardholder, transacDate, transType, "", Integer.parseInt(responsecode), true, Integer.parseInt(amount));
            
            String fraud = getListFraud(transac);
            transac.setFraudStandardCheck(fraud);
            
            ModelAndView mv = new ModelAndView("DetailTransaction");
            
            List<Fraudstandard> lstFraud = new ArrayList<Fraudstandard>();
            
            if(fraud.equals("none"))
            {
                transac.setIsFraud(false);
            }
            else
            {
                String[] lst = fraud.split(",");
                for(int i=1;i<lst.length;i++)
                {
                    int id = Integer.parseInt(lst[i]);
                    Fraudstandard fr = fraudBUS.getFraudStandardById(id);
                    lstFraud.add(fr);
                }
            }
            
            personBUS.savePerson(buyer);
            personBUS.savePerson(receiver);
            transBUS.saveTransaction(transac);
            
            mv.addObject("lstFraud", lstFraud);
            mv.addObject("transac", transac);
            return mv;
        }
 }
    
    private String getListFraud(Transactions trans) throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException {
        
        String listFraud="none";
        
        List<Fraudstandard> lstFraud = fraudBUS.listfraudStandards();
        for (Iterator iterator = (Iterator) lstFraud.iterator();iterator.hasNext();)
        {
             Fraudstandard fraud = (Fraudstandard) iterator.next();
             
             if(fraud.getFraudstandardId() == 1) {
                 try { // So lan nhap sai CVV - CVC trong 1 ngay cua 1 the, tra bang response code == 4
                    List<Transactions> lstTrans = transBUS.listTransactions("cardnumber",trans.getCardnumber());
                    int dem = 0;
                    for (Iterator itr = (Iterator) lstTrans.iterator();iterator.hasNext();)
                    {
                        Transactions tr = (Transactions) itr.next();
                        if (tr.getResponseCode() == 4 && tr.getTransactionDate() == trans.getTransactionDate())
                            dem++;
                    }
                    if(trans.getTransactionType().equalsIgnoreCase("Domestic")) {
                        if(dem > fraud.getDomesticLimit())
                        {
                            listFraud = listFraud + ",1";
                        }
                    }
                    else{
                        if(dem > fraud.getForeignLimit())
                        {
                            listFraud = listFraud + ",1";
                        }
                    }
                        
                 }
                 catch(Exception e) {
                 }
                 
             }
             else if(fraud.getFraudstandardId() == 2) {
                 try { // So lan nhap sai CVV - CVC trong 2 ngay cua 1 the, tra bang response code == 4
                    List<Transactions> lstTrans = transBUS.listTransactions("cardnumber",trans.getCardnumber());
                    int dem = 0;
                    for (Iterator itr = (Iterator) lstTrans.iterator();iterator.hasNext();)
                    {
                        Transactions tr = (Transactions) itr.next();
                        if (tr.getResponseCode() == 4 && (tr.getTransactionDate() == trans.getTransactionDate() || tr.getTransactionDate() == getYesterday(trans.getTransactionDate())))
                            dem++;
                        if(trans.getTransactionType().equalsIgnoreCase("Domestic")) {
                            if(dem > fraud.getDomesticLimit())
                            {
                                listFraud = listFraud + ",2";
                                break;
                            }
                        }
                        else{
                            if(dem > fraud.getForeignLimit())
                            {
                                listFraud = listFraud + ",2";
                                break;
                            }
                        }
                    }
                        
                 }
                 catch(Exception e) {
                 }
             }
             else if(fraud.getFraudstandardId() == 3) {
                 try { // So lan nhap sai Expiry Date trong 1 ngay cua 1 the, tra bang response code == 3
                    List<Transactions> lstTrans = transBUS.listTransactions("cardnumber",trans.getCardnumber());
                    int dem = 0;
                    for (Iterator itr = (Iterator) lstTrans.iterator();iterator.hasNext();)
                    {
                        Transactions tr = (Transactions) itr.next();
                        if (tr.getResponseCode() == 3 && (tr.getTransactionDate().getTime() == trans.getTransactionDate().getTime()))
                            dem++;
                        
                        if(trans.getTransactionType().equalsIgnoreCase("Domestic")) {
                            if(dem > fraud.getDomesticLimit())
                            {
                                listFraud = listFraud + ",3";
                                break;
                            }
                        }
                        else{
                            if(dem > fraud.getForeignLimit())
                            {
                                listFraud = listFraud + ",3";
                                break;
                            }
                        }
                    }
                    
                        
                 }
                 catch(Exception e) {
                 }
             }
             else if(fraud.getFraudstandardId() == 4) {
                 try { // So lan nhap sai Expiry Date trong 2 ngay cua 1 the, tra bang response code == 3
                    List<Transactions> lstTrans = transBUS.listTransactions("cardnumber",trans.getCardnumber());
                    int dem = 0;
                    for (Iterator itr = (Iterator) lstTrans.iterator();iterator.hasNext();)
                    {
                        Transactions tr = (Transactions) itr.next();
                        if (tr.getResponseCode() == 3 && (tr.getTransactionDate() == trans.getTransactionDate() || tr.getTransactionDate() == getYesterday(trans.getTransactionDate())))
                            dem++;
                        if(trans.getTransactionType().equalsIgnoreCase("Domestic")) {
                            if(dem > fraud.getDomesticLimit())
                            {
                                listFraud = listFraud + ",4";
                                break;
                            }
                        }
                        else{
                            if(dem > fraud.getForeignLimit())
                            {
                                listFraud = listFraud + ",4";
                                break;
                            }
                        }
                    }
                    
                        
                 }
                 catch(Exception e) {
                 }
             }
             else if(fraud.getFraudstandardId() == 5) {
                 try { // DVCNT co gia tri giao dich tang so voi gia tri giao dich cua ngay lien truoc
                    int amount_yesterday = transBUS.SumAmountInADay(trans.getMerchantCode(), getYesterday(trans.getTransactionDate()), trans.getCardnumber());
                    int amount_today = transBUS.SumAmountInADay(trans.getMerchantCode(), trans.getTransactionDate(), trans.getCardnumber());
                    if(trans.getTransactionType().equalsIgnoreCase("Domestic")) {
                        if((amount_today - amount_yesterday) > fraud.getDomesticLimit()*1000000)
                        {
                            listFraud = listFraud + ",5";
                        }
                    }
                    else{
                        if((amount_today - amount_yesterday) > fraud.getForeignLimit()*1000000)
                        {
                            listFraud = listFraud + ",5";
                        }
                    }
                        
                 }
                 catch(Exception e) {
                 }
             }
             else if(fraud.getFraudstandardId() == 6) {
                 try { // dvcnt co gia tri giao dich tang so voi gia tri giao dich binh quan thang cua DVCNT
                    int amount_avg = transBUS.AvgAmountInMonth(trans.getMerchantCode(), trans.getTransactionDate().getMonth(), trans.getCardnumber());
                    int amount_today = transBUS.SumAmountInADay(trans.getMerchantCode(), trans.getTransactionDate(), trans.getCardnumber());
                    if(trans.getTransactionType().equalsIgnoreCase("Domestic")) {
                        if((amount_today - amount_avg) > fraud.getDomesticLimit()*1000000)
                        {
                            listFraud = listFraud + ",6";
                        }
                    }
                    else{
                        if((amount_today - amount_avg) > fraud.getForeignLimit()*1000000)
                        {
                            listFraud = listFraud + ",6";
                        }
                    }
                        
                 }
                 catch(Exception e) {
                 }
             }
             else if(fraud.getFraudstandardId() == 7) {
                 try { // tong so giao dich bi tu choi cap phep trong 1 ngay tu 1 the, tra bang response code != 0
                    List<Transactions> lstTrans = transBUS.listTransactions("cardnumber",trans.getCardnumber());
                    int dem = 0;
                    for (Iterator itr = (Iterator) lstTrans.iterator();iterator.hasNext();)
                    {
                        Transactions tr = (Transactions) itr.next();
                        if (tr.getResponseCode() != 0 && (tr.getTransactionDate() == trans.getTransactionDate()))
                            dem++;
                        if(trans.getTransactionType().equalsIgnoreCase("Domestic")) {
                            if(dem > fraud.getDomesticLimit()*1000000)
                            {
                                listFraud = listFraud + ",7";
                            }
                        }
                        else{
                            if(dem > fraud.getForeignLimit())
                            {
                                listFraud = listFraud + ",7";
                            }
                        }
                    }
                    
                        
                 }
                 catch(Exception e) {
                 }
             }
             else if(fraud.getFraudstandardId() == 8) {
                 try { // tong so giao dich bi tu choi cap phep trong 2 ngay tu 1 the, tra bang response code != 0
                    List<Transactions> lstTrans = transBUS.listTransactions("cardnumber",trans.getCardnumber());
                    int dem = 0;
                    for (Iterator itr = (Iterator) lstTrans.iterator();iterator.hasNext();)
                    {
                        Transactions tr = (Transactions) itr.next();
                        if (tr.getResponseCode() !=0 && (tr.getTransactionDate() == trans.getTransactionDate() || tr.getTransactionDate() == getYesterday(trans.getTransactionDate())))
                            dem++;
                        if(trans.getTransactionType().equalsIgnoreCase("Domestic")) {
                            if(dem > fraud.getDomesticLimit())
                            {
                                listFraud = listFraud + ",8";
                            }
                        }
                        else{
                            if(dem > fraud.getForeignLimit())
                            {
                                listFraud = listFraud + ",8";
                            }
                        }
                    }
                    
                        
                 }
                 catch(Exception e) {
                 }
             }
             else if(fraud.getFraudstandardId() == 9) {
                 try { // tong so giao dich thuc hien trong 1 ngay tu 1 the
                    List<Transactions> lstTrans = transBUS.listTransactions("cardnumber",trans.getCardnumber());
                    int dem = 0;
                    for (Iterator itr = (Iterator) lstTrans.iterator();iterator.hasNext();)
                    {
                        Transactions tr = (Transactions) itr.next();
                        if (tr.getTransactionDate() == trans.getTransactionDate() )
                            dem++;
                        if(trans.getTransactionType().equalsIgnoreCase("Domestic")) {
                            if(dem > fraud.getDomesticLimit())
                            {
                                listFraud = listFraud + ",9";
                            }
                        }
                        else{
                            if(dem > fraud.getForeignLimit())
                            {
                                listFraud = listFraud + ",9";
                            }
                        }
                    }
                    
                        
                 }
                 catch(Exception e) {
                 }
             }
             else if(fraud.getFraudstandardId() == 10) {
                 try { // tong so giao dich thuc hien trong 2 ngay tu 1 the
                    List<Transactions> lstTrans = transBUS.listTransactions("cardnumber",trans.getCardnumber());
                    int dem = 0;
                    for (Iterator itr = (Iterator) lstTrans.iterator();iterator.hasNext();)
                    {
                        Transactions tr = (Transactions) itr.next();
                        if (tr.getTransactionDate() == trans.getTransactionDate() || tr.getTransactionDate() == getYesterday(trans.getTransactionDate()))
                            dem++;
                        if(trans.getTransactionType().equalsIgnoreCase("Domestic")) {
                            if(dem > fraud.getDomesticLimit())
                            {
                                listFraud = listFraud + ",10";
                            }
                        }
                        else{
                            if(dem > fraud.getForeignLimit())
                            {
                                listFraud = listFraud + ",10";
                            }
                        }
                    }
                    
                        
                 }
                 catch(Exception e) {
                 }
             }
             else if(fraud.getFraudstandardId() == 11) {
                 try { // tong so giao dich thanh cong thuc hien trong 1 ngay tu 1 the, tra bang response code ==0 
                    List<Transactions> lstTrans = transBUS.listTransactions("cardnumber",trans.getCardnumber());
                    int dem = 0;
                    for (Iterator itr = (Iterator) lstTrans.iterator();iterator.hasNext();)
                    {
                        Transactions tr = (Transactions) itr.next();
                        if (tr.getResponseCode() == 0 && (tr.getTransactionDate() == trans.getTransactionDate()))
                            dem++;
                        if(trans.getTransactionType().equalsIgnoreCase("Domestic")) {
                            if(dem > fraud.getDomesticLimit())
                            {
                                listFraud = listFraud + ",11";
                            }
                        }
                        else{
                            if(dem > fraud.getForeignLimit())
                            {
                                listFraud = listFraud + ",11";
                            }
                        }
                    }
                    
                        
                 }
                 catch(Exception e) {
                 }
             }
             else if(fraud.getFraudstandardId() == 12) {
                 try { // tong so giao dich thanh con trong 2 ngay tu 1 the, tra bang response code ==0
                    List<Transactions> lstTrans = transBUS.listTransactions("cardnumber",trans.getCardnumber());
                    int dem = 0;
                    for (Iterator itr = (Iterator) lstTrans.iterator();iterator.hasNext();)
                    {
                        Transactions tr = (Transactions) itr.next();
                        if (tr.getResponseCode() == 0 && (tr.getTransactionDate() == trans.getTransactionDate() || tr.getTransactionDate() == getYesterday(trans.getTransactionDate())))
                            dem++;
                        if(trans.getTransactionType().equalsIgnoreCase("Domestic")) {
                            if(dem > fraud.getDomesticLimit())
                            {
                                listFraud = listFraud + ",12";
                            }
                        }
                        else{
                            if(dem > fraud.getForeignLimit())
                            {
                                listFraud = listFraud + ",12";
                            }
                        }
                    }
                    
                        
                 }
                 catch(Exception e) {
                 }
             }
             else if(fraud.getFraudstandardId() == 13) {
                 try { // tong gia tri giao dich thuc hien trong 1 ngay tu 1 the
                    //int amount_yesterday = transBUS.SumAmountInADay(getYesterday(trans.getTransactionDate()), trans.getCardnumber());
                    int amount_today = transBUS.SumAmountInADay(trans.getTransactionDate(), trans.getCardnumber());
                    if(trans.getTransactionType().equalsIgnoreCase("Domestic")) {
                        if((amount_today) > fraud.getDomesticLimit()*1000000)
                        {
                            listFraud = listFraud + ",5";
                        }
                    }
                    else{
                        if((amount_today) > fraud.getForeignLimit()*1000000)
                        {
                            listFraud = listFraud + ",5";
                        }
                    }
                        
                 }
                 catch(Exception e) {
                 }
             }
             else if(fraud.getFraudstandardId() == 14) {
                 try { // Tong gia tri giao dich thuc hien trong 2 ngay tu 1 the
                    int amount_yesterday = transBUS.SumAmountInADay(getYesterday(trans.getTransactionDate()), trans.getCardnumber());
                    int amount_today = transBUS.SumAmountInADay(trans.getTransactionDate(), trans.getCardnumber());
                    if(trans.getTransactionType().equalsIgnoreCase("Domestic")) {
                        if((amount_today + amount_yesterday) > fraud.getDomesticLimit()*1000000)
                        {
                            listFraud = listFraud + ",5";
                        }
                    }
                    else{
                        if((amount_today + amount_yesterday) > fraud.getForeignLimit()*1000000)
                        {
                            listFraud = listFraud + ",5";
                        }
                    }
                        
                 }
                 catch(Exception e) {
                 }
             }
             else if(fraud.getFraudstandardId() == 15) {
                  try { // Kiem trung transactionId
                    List<Transactions> lstTrans = transBUS.listTransactions();
                    int dem = 0;
                    for (Iterator itr = (Iterator) lstTrans.iterator();iterator.hasNext();)
                    {
                        Transactions tr = (Transactions) itr.next();
                        if (tr.getTransactionId().equals(trans.getTransactionId()))
                            dem++;
                        if(trans.getTransactionType().equalsIgnoreCase("Domestic")) {
                            if(dem > fraud.getDomesticLimit())
                            {
                                listFraud = listFraud + ",15";
                            }
                        }
                        else{
                            if(dem > fraud.getForeignLimit())
                            {
                                listFraud = listFraud + ",15";
                            }
                        }
                    }
                    
                        
                 }
                 catch(Exception e) {
                 }
             }
             else if(fraud.getFraudstandardId() == 16) {
                 try {// Kiem tra the black
                     List<Cardblacklist> lstCardblack = cardblackBUS.listCardblacklist();
                     for (Iterator itr = (Iterator) lstCardblack.iterator();iterator.hasNext();)
                    {
                        Cardblacklist cardBlack = (Cardblacklist) itr.next();
                        if (cardBlack.getCard().getCardnumber().equals(trans.getCardnumber())){
                                listFraud = listFraud + ",16";
                                break;
                        }
                    }
                 }
                 catch (Exception e) {
                 }
                 
                 
             }
             else if(fraud.getFraudstandardId() == 17) {
                 try {// Kiem tra ip black
                     List<Ipblacklist> lstIpblack = ipblackBUS.listIpblacklist();
                     for (Iterator itr = (Iterator) lstIpblack.iterator();iterator.hasNext();)
                    {
                        Ipblacklist ipblack = (Ipblacklist) itr.next();
                        if (ipblack.getIp().getIp().equals(trans.getIp())){
                                listFraud = listFraud + ",17";
                                break;
                        }
                    }
                 }
                 catch (Exception e) {
                 }
             }
             else if(fraud.getFraudstandardId() == 18) {
                 // gia tri giao dich
                 if(trans.getTransactionType().equalsIgnoreCase("Domestic")) {
                    if(trans.getAmount() > fraud.getDomesticLimit()) 
                    {
                        listFraud = listFraud + ",18";
                    }
                }
                else{
                    if(trans.getAmount() > fraud.getForeignLimit())
                    {
                        listFraud = listFraud + ",18";
                    }
                }
                     
             }
        }
        return listFraud;
    }
    
    private Boolean getgender(String gender) {
        if(gender.equals("M"))
            return true;
        return false;
    }
    
    private Date getYesterday(Date today)
    {
        long oneDayInMillis = 1000 * 60 * 60 * 24;
        long yesterday = today.getTime() - oneDayInMillis;
        Date yday = new Date(yesterday);
        
        return yday;
    }
    
    @Override
    protected ModelAndView showForm(HttpServletRequest request, 
        HttpServletResponse response, BindException errors) throws Exception {
        
        ModelAndView mv = super.showForm(request, response, errors);
        
        List<Merchant> lstDvcnt = dvcntBUS.listDvcnt();
        mv.addObject("lstDvcnt",lstDvcnt);
        
        List<Countries> lstCountries = cityBUS.listCountries();
        mv.addObject("lstCountries",lstCountries);
        
        List<Cities> lstCities = cityBUS.listCities();
        mv.addObject("lstCities",lstCities);
        
        return mv;
    }
    
//    
//    @Override
//    protected void doSubmitAction(Object command) throws Exception {
//        throw new UnsupportedOperationException("Not yet implemented");
//    }
    //Use onSubmit instead of doSubmitAction 
    //when you need access to the Request, Response, or BindException objects
    
//    @Override
//    protected ModelAndView onSubmit(
//    HttpServletRequest request, 
//    HttpServletResponse response, 
//    Object command, 
//    BindException errors) throws Exception {
//        ModelAndView mv = new ModelAndView(getSuccessView());
//        //Do something...
//        return mv;
//    }
     
}
